package com.greateamd.timetableasy.server.services;

import java.util.List;

import org.springframework.stereotype.Service;

import com.greateamd.timetableasy.client.services.event.EventService;
import com.greateamd.timetableasy.domain.Event;
import com.greateamd.timetableasy.domain.exceptions.DBServerSideException;
import com.greateamd.timetableasy.server.dao.EventDAO;

@Service("eventService")
public class EventServiceImpl implements EventService {

	private EventDAO eventDAO;
	public void setEventDAO(EventDAO eventDAO) {
		this.eventDAO = eventDAO;
	}
	
	@Override
	public boolean save(Event event) throws DBServerSideException {
		try {
			eventDAO.save(event);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
		return true;
	}

	@Override
	public Event find(int id) throws DBServerSideException{
		try {
			return eventDAO.getById(id);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public List<Event> getAll() throws DBServerSideException {
		try {
			return eventDAO.getAll();
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean remove(Event event) throws DBServerSideException {
		try {
			eventDAO.delete(event);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean update(Event event) throws DBServerSideException {
		try {
			eventDAO.update(event);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

}
